import React from 'react';
import {Switch,Route,Redirect} from "react-router-dom"
import {adminRoutes} from "./routes/index.js"
import Frame from "./components/Frame.js"
import "./app.css"
//进入这个组件之前判断是否有token，若果有就进入app组件，否则跳转到login界面
function App() {
	//定义一个获取token的函数
	function getToken() {
	  return localStorage.getItem("token");
	}
  return getToken()?(
    <Frame>
		<Switch>
			{
				adminRoutes.map(route=>{
					return(
						<Route 
						key={route.path} 
						path={route.path} 
						exact={route.exact} 
						render={routeProps=>{
							return <route.component {...routeProps} />
						}} 
						/>
					)
				})
			}
			<Redirect to={adminRoutes[0].path} from="/admin" />
			<Redirect to="/404" />
		</Switch>
    </Frame>
  ):(<Redirect to="/login" />);
}

export default App;
